package com.kgc.server.controller;

import com.kgc.server.service.OrderService;
import com.kgc.server.util.ResponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class EasybuyOrderController {

    @Autowired
    private OrderService orderService;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping("addOrder")
    @ResponseBody
    @CrossOrigin
    public ResponseMessage addOrder(String userId){
        logger.info("EasybuyOrderController addOrder params: userId:"+userId);
        ResponseMessage msg = orderService.addOrder(userId);
        return msg;
    }

    @RequestMapping("getOrderBySerialNumber")
    @ResponseBody
    @CrossOrigin
    public ResponseMessage getOrderBySerialNumber(String s){
        logger.info("EasybuyOrderController getOrderBySerialNumber(String s:"+s+")");
        ResponseMessage msg = orderService.getOrderBySerialNumber(s);
        logger.info("EasybuyOrderController getOrderBySerialNumber(String s:"+s+")msg:"+msg);
        return msg;
    }

    @RequestMapping("getOrdersByUserId")
    @ResponseBody
    @CrossOrigin
    public ResponseMessage getOrdersByUserId(String userId,String serialNumber,Integer pageNo){
        logger.info("EasybuyOrderController getOrdersByUserId params: userId"+userId+";serialNumber"+serialNumber+";pageNo:"+pageNo);
        ResponseMessage ordersByUserId = orderService.getOrdersByUserId(userId, serialNumber, pageNo);
        return ordersByUserId;
    }

    @RequestMapping("getOAndP")
    @ResponseBody
    @CrossOrigin
    public ResponseMessage getOAndP(String oId){
        logger.info("ResponseMessage getOAndP(String oId:"+oId+")");
        ResponseMessage msg = orderService.getOAndP(oId);
        logger.info("ResponseMessage getOAndP(String oId:"+oId+")msg"+msg);
        return msg;
    }

}
